package io.github.yotta.export.web.simple;

import io.github.yotta.common.api.model.Paging;
import io.github.yotta.export.core.model.ExecuteContext;
import io.github.yotta.export.web.iface.SpringExcelDataExporter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author yotta
 * @date 2023/10/31 18:16
 */
@Component
@Slf4j
public class UserAsyncExporter implements SpringExcelDataExporter<UserExportModel, UserExportParam> {

    private final UserService userService;

    public UserAsyncExporter(UserService userService) {
        this.userService = userService;
    }

    @Override
    public Paging<UserExportModel> exportData(UserExportParam exportParam, ExecuteContext context) {
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Paging<UserExportModel> page = userService.page(exportParam);
        log.info("导出数据完成");
        return page;
    }

    @Override
    public String exportFileName(UserExportParam exportParam, ExecuteContext context) {
        return "用户数据导出接口实现";
    }
}
